package com.markerhub.modules.admin;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.markerhub.common.dto.AddGroupDto;
import com.markerhub.common.dto.LoginDto;
import com.markerhub.common.lang.Result;
import com.markerhub.entity.AppBlueLabel;
import com.markerhub.entity.AppGroupType;
import com.markerhub.modules.common.BaseController;
import com.markerhub.service.AppGroupTypeService;
import com.markerhub.service.AppUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Slf4j
@RestController
@RequestMapping("/admin")
public class AdminGroupController extends BaseController {

    @Resource
    AppGroupTypeService mAppGroupTypeService;

    @PostMapping("/group/setGroup")
    public Result login(@Validated @RequestBody AddGroupDto mAddGroupDto) {
        AppGroupType mAppGroupType=new AppGroupType();
        mAppGroupType.setGroupArea(mAddGroupDto.getGrouparea());
        mAppGroupType.setGroupName(mAddGroupDto.getGroupname());
        int result = mAppGroupTypeService.insertGroup(mAppGroupType);
        log.info("插入成功"+mAddGroupDto.toString());
        if (result==1){
            return Result.success("success");
        }else{
            return Result.fail("重复数据存在");
        }
    }



    @GetMapping("/getGroupList")
    public Result list(AppGroupType appOrder) {
        Object pageAdmin = mAppGroupTypeService.pageAdmin(getPage(), appOrder);
        Page<AppBlueLabel> data= (Page<AppBlueLabel>) pageAdmin;
        return Result.success(MapUtil.builder()
                .put("pageData", data)
                .build()
        );
    }


}